<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" id="i1" placeholder="请输入1-100之间的整数">
<input type="button"value="猜一猜" onclick="fn()">
<div></div>

<script>
    // 获取随机整数1-100之间随机整数
    let x=parseInt(Math.random()*100+1);
    let num=0;
    function fn(){
        let i=document.querySelector("#i1");
        let d=document.querySelector("div");
    //    拿用户输入的值和上面得到的随机整数作比较

            num++;
            if (i.value<x){
                d.innerText="猜小了";
            }else if(i.value>x){
                d.innerText="猜大了";
            }else {
                d.innerText="恭喜第"+num+"次猜对了";
            }
    }

</script>
</body>
</html>